package top.superflow.flow.config.parse.center

import top.superflow.exception.RequestUnsupportedException
import top.superflow.flow.config.ResourceConfig
import top.superflow.flow.config.parse.impl.ResourceConfigParser

class ResourceConfigParserCenter private () extends ParserCenter[ResourceConfig, ResourceConfigParser] {

  def getParser(resourceConfig : ResourceConfig) : ResourceConfigParser = {
    if(resourceConfig == null){
      throw new RequestUnsupportedException("The resource config should not be null!")
    }
    val resourceType = resourceConfig.getResourceType

    val resourceConfigParser = this.getParser(resourceType)
    if(resourceConfigParser == null){
      throw new RequestUnsupportedException("There is no registered parser for the resource type " + resourceType)
    }

    resourceConfigParser
  }

}

object ResourceConfigParserCenter {
  private final val instance = new ResourceConfigParserCenter

  def getInstance = instance
}
